package com.dayuanit.atm.runnable;

import com.dayuanit.atm.handler.ATMWebSocketHandler;
import com.dayuanit.atm.handler.MessageHolder;

public class MessageRunnable implements Runnable {

    private MessageHolder messageHolder;

    public MessageRunnable(int userId, String message) {

        MessageHolder messageHolder = new MessageHolder();
        messageHolder.setUserId(userId);
        messageHolder.setMessage(message);
        this.messageHolder = messageHolder;
    }

    @Override
    public void run() {
        System.out.println(">>>>>>>>>>>>>>>>发送消息的线程启动...");
        while (true) {
            try {
                System.out.println(">>>>>>>>>>>>>>>>从消息队列获取到消息 userid = " + messageHolder.getUserId());
                ATMWebSocketHandler.sendMessage(messageHolder);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }
}
